package com.lunago.agent.controller;

import com.lunago.agent.constant.JsonResult;
import com.lunago.agent.jwt.JwtPayLoad;
import com.lunago.agent.pojo.dto.ChatQuery;
import com.lunago.agent.pojo.entity.ChatRecord;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 处理测试单点登录相关请求的控制器类
 *
 * @author java@tedu.cn
 * @version 3.0
 */
@RestController
@RequestMapping("/aichat")
@Api(tags = "3. 测试访问")
public class TestController {

    @Autowired
    private MongoTemplate mongoTemplate;

    @PostMapping("/test/clear-chat-records")
    public JsonResult clearChatRecords(@AuthenticationPrincipal JwtPayLoad payload) {
        Long userId = payload.getUserId();
        Query query = new Query(Criteria.where("userId").is(userId));
        mongoTemplate.remove(query, "chat_record");
        return JsonResult.ok();
    }
}
